//===================================================================
// IS2Cannon
//
// Copyright (C) 2004 John "Ramm-Jaeger"  Gibson
//
// IS-2 tank cannon class
//===================================================================
class IS2Cannon extends ONSWeapon;
#exec OBJ LOAD FILE=..\Animations\tank_a.ukx
#exec OBJ LOAD FILE=..\Textures\tank_t.utx
var vector OldDir;
var rotator OldRot;


simulated function UpdatePrecacheStaticMeshes()
{

	Super.UpdatePrecacheStaticMeshes();
}

function byte BestMode()
{
	return 0;
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	OldDir = Vector(CurrentAim);
}

function Tick(float Delta)
{
	local int i;
	local xPawn P;
	local vector NewDir, PawnDir;
	local coords WeaponBoneCoords;


	Super.Tick(Delta);

	if ( (Role == ROLE_Authority) && (Base != None) )
	{
		WeaponBoneCoords = GetBoneCoords(YawBone);
		NewDir = WeaponBoneCoords.XAxis;
		if ( (Vehicle(Base).Controller != None) && (NewDir.Z < 0.9) )
		{
			for ( i=0; i<Base.Attached.Length; i++ )
			{
				P = XPawn(Base.Attached[i]);
				if ( (P != None) && (P.Physics != PHYS_None) && (P != Vehicle(Base).Driver) )
				{
					PawnDir = P.Location - WeaponBoneCoords.Origin;
					PawnDir.Z = 0;
					PawnDir = Normal(PawnDir);
					if ( ((PawnDir.X <= NewDir.X) && (PawnDir.X > OldDir.X))
						|| ((PawnDir.X >= NewDir.X) && (PawnDir.X < OldDir.X)) )
					{
						if ( ((PawnDir.Y <= NewDir.Y) && (PawnDir.Y > OldDir.Y))
							|| ((PawnDir.Y >= NewDir.Y) && (PawnDir.X < OldDir.Y)) )
						{
							P.SetPhysics(PHYS_Falling);
							P.Velocity = WeaponBoneCoords.YAxis;
							if ( ((NewDir - OldDir) Dot WeaponBoneCoords.YAxis) < 0 )
								P.Velocity *= -1;
							P.Velocity = 500 * (P.Velocity + 0.3*NewDir);
							P.Velocity.Z = 200;
						}
					}
				}
			}
		}
		OldDir = NewDir;
	}
}

defaultproperties
{
     YawBone="Turret"
     PitchBone="Gun"
     PitchUpLimit=6000
     PitchDownLimit=64000
     WeaponFireAttachmentBone="Gun"
     WeaponFireOffset=200.000000
     RotationsPerSecond=0.070000
     FireInterval=4.000000
     EffectEmitterClass=Class'ROEffects.TankCannonFireEffect'
     FireSoundClass=SoundGroup'KF_LAWSnd.LAW_Fire'
     FireSoundVolume=512.000000
     FireForce="Explosion05"
     ProjectileClass=Class'PerksSimHostOrg.RPGWProj4'
     ShakeRotMag=(Z=250.000000)
     ShakeRotRate=(Z=2500.000000)
     ShakeRotTime=6.000000
     ShakeOffsetMag=(Z=10.000000)
     ShakeOffsetRate=(Z=200.000000)
     ShakeOffsetTime=10.000000
     AIInfo(0)=(bLeadTarget=True,WarnTargetPct=0.750000,RefireRate=0.500000)
     AIInfo(1)=(bLeadTarget=True,WarnTargetPct=0.750000,RefireRate=0.015000)
     Mesh=SkeletalMesh'tank_a.IS2_turret_ext'
     Skins(0)=Texture'tank_t.IS2_ext'
     Skins(1)=Texture'tank_t.IS2_int'
     SoundVolume=130
}
